package com.example.cd5160866.urlapp;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.LayoutInflaterCompat;
import android.support.v4.view.LayoutInflaterFactory;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


public class Demo4Activity extends AppCompatActivity {
    TextView textView2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LayoutInflaterCompat.setFactory(LayoutInflater.from(this), new LayoutInflaterFactory() {
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                Log.d("qw", "---" + name + "---");
                int setCount = attrs.getAttributeCount();

                for (int i = 0; i < setCount; i++) {
                    Log.d("qw", attrs.getAttributeName(i) + " : " + attrs.getAttributeValue(i));
                }

                if(getDelegate()!=null){
                    View view = getDelegate().createView(parent,name,context,attrs);

                    return view;
                }
                Log.d("qw", "----------");
                //                if ("TextView".equalsIgnoreCase(name)) {
                //                    return new CheckBox(context, attrs);
                //                }
                return null;
            }
        });

        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo_4);
        textView2 = (TextView) findViewById(R.id.tv_tv2);
        findViewById(R.id.tv_tv1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("qw", v.getClass().getSimpleName());
                textView2.setShadowLayer(12, 12, 12, Color.RED);
            }
        });
        findViewById(R.id.tv_tv2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                findViewById(R.id.child).setVisibility(View.GONE);
            }
        });
        findViewById(R.id.tv_tv2).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                findViewById(R.id.child).setVisibility(View.VISIBLE);
                return true;
            }
        });
        findViewById(R.id.child).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setVisibility(View.INVISIBLE);
            }
        });



    }


    //        LayoutInflaterCompat.setFactory(LayoutInflater.from(this), new LayoutInflaterFactory() {
    //            @Override
    //            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    //                Log.d("qw", "---" + name + "---");
    //                int setCount = attrs.getAttributeCount();
    //
    //                for (int i = 0; i < setCount; i++) {
    //                    Log.d("qw", attrs.getAttributeName(i) + " : " + attrs.getAttributeValue(i));
    //                }
    //
    //                Log.d("qw", "----------");
    //                if("TextView".equalsIgnoreCase(name)){
    //                    return new CheckBox(context,attrs);
    //                }
    //                return null;
    //            }
    //        });
}
